from django.shortcuts import render_to_response
from django.views.decorators.csrf import csrf_protect
from django.template import RequestContext
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _

from itertools import izip as zip
from itertools import imap as map

from utils.views import set_language

MENU_LANGUAGES = {
    'en': (_('English'), u'English'),
    'de': (_('German'), u'Deutsch'),
    'es': (_('Spanish'), u'Espa\u00f1ol'),
    'ru': (_('Russian'), u'\u0420\u0443\u0441\u0441\u043a\u0438\u0439'),
    'zh-cn': (_('Simplified Chinese'), u'\u7b80\u4f53\u4e2d\u6587'),
    'zh-tw': (_('Traditional Chinese'), u'\u7e41\u9ad4\u4e2d\u6587'),
    }

SORTED_LANG_CODE = sorted(MENU_LANGUAGES.keys())

@csrf_protect
def settings_f(request):
    return render_to_response('polls/settings_f.html',
        {'next': request.GET.get('next') or reverse('polls-index', args=(request.LANGUAGE_CODE,)),
         'supports_language': request.LANGUAGE_CODE in MENU_LANGUAGES,
         'languages': zip(SORTED_LANG_CODE, map(MENU_LANGUAGES.__getitem__, SORTED_LANG_CODE))},
        context_instance=RequestContext(request))
 
@csrf_protect   
def settings(request):
    response = set_language(request)
    return response